package com.bjwl.display.service.safty.impl;

import com.bjwl.display.exception.SysException;
import com.bjwl.display.mapper.safty.UserMapper;
import com.bjwl.display.model.Role;
import com.bjwl.display.model.User;
import com.bjwl.display.service.safty.UserService;
import com.bjwl.display.vo.UserRegisterVO;
import org.omg.CORBA.INTERNAL;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;
    @Override
    public boolean register(UserRegisterVO userRegisterVO) {
        try {
            boolean us = userMapper.addUser(new User(userRegisterVO.getU_id(),userRegisterVO.getU_name(),userRegisterVO.getU_pwd(),null));
            //在添加用户的同时给他赋予相应的角色
            Map<String,Object> map = new HashMap<>();
            map.put("u_id",userRegisterVO.getU_id());
            map.put("ro_id",userRegisterVO.getRo_id());
            boolean ro = userMapper.addrole(map);

            if(us==true&&ro==true){
                return true;
            }
            return false;
        } catch (Exception e) {
            e.printStackTrace();
            throw new SysException("系统错误");
        }

    }
}
